package com.sojson.project.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sojson.config.exception.TransErrorCode;
import com.sojson.project.controller.param.verify.CouponStoreParamVerify;
import com.sojson.project.entity.po.CouponStore;
import com.sojson.project.service.CouponStoreService;
import com.sojson.result.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 券可用店铺控制器
 * 
 * @author liu
 * @date 2021-06-02
 */
@Api(tags = "券可用店铺管理")
@RestController
@RequestMapping("/couponStore")
public class CouponStoreController {

    @Autowired
    private CouponStoreService couponStoreService;

    /**
     * 单条插入
     * 
     * @param couponStore
     * @return
     */
    @PostMapping("/insert")
    @PreAuthorize("@ss.hasPermi('/couponStore/insert')")
    @ApiOperation("给券可用店铺添加一条数据")
    public Result<Integer> insert(@RequestBody CouponStore couponStore) {
        // 校验参数
        Result<Integer> paramResult = CouponStoreParamVerify.insert(couponStore);
        // 验证不通过
        if (!paramResult.getCode().equals(TransErrorCode.SUCCESS.getCode())) {
            return paramResult;
        }

        couponStore.insertInit();
        return Result.success(couponStoreService.insert(couponStore));
    }

    /**
     * 批量插入
     * 
     * @param couponStore
     * @return
     */
    @PostMapping("/insertList")
    @PreAuthorize("@ss.hasPermi('/couponStore/insertList')")
    @ApiOperation("给券可用店铺添加多条数据")
    public Result<Integer> insertList(@RequestBody CouponStore couponStore) {
        return Result.success(couponStoreService.insertList(couponStore));
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param couponStore
     * @return
     */
    @DeleteMapping("/deleteByDto")
    @PreAuthorize("@ss.hasPermi('/couponStore/deleteByDto')")
    @ApiOperation("通过对象批量删除券可用店铺数据(物理删除)")
    public Result<Integer> deleteByDto(@RequestBody CouponStore couponStore) {
        return Result.success(couponStoreService.deleteByDto(couponStore));
    }

    /**
     * 统计全部数量
     * 
     * @return
     */
    @GetMapping("/countAll")
    @PreAuthorize("@ss.hasPermi('/couponStore/countAll')")
    @ApiOperation("统计券可用店铺全部数据(包含逻辑删除的)")
    public Result<Integer> countAll() {
        return Result.success(couponStoreService.countAll());
    }

    /**
     * 查询所有
     * 
     * @return
     */
    @GetMapping("/listAll")
    @PreAuthorize("@ss.hasPermi('/couponStore/listAll')")
    @ApiOperation("查询券可用店铺所有数据(包含逻辑删除的)")
    public Result<List<CouponStore>> listAll() {
        return Result.success(couponStoreService.listAll());
    }

    /**
     * 根据对象统计数量
     * 
     * @param couponStore
     * @return
     */
    @GetMapping("/countByDto")
    @PreAuthorize("@ss.hasPermi('/couponStore/countByDto')")
    @ApiOperation("根据对象统计券可用店铺数据")
    public Result<Integer> countByDto(CouponStore couponStore) {
        return Result.success(couponStoreService.countByDto(couponStore));
    }

    /**
     * 根据对象查询
     * 
     * @param couponStore
     * @return
     */
    @GetMapping("/listByDto")
    @PreAuthorize("@ss.hasPermi('/couponStore/listByDto')")
    @ApiOperation("根据对象查询券可用店铺数据")
    public Result<List<CouponStore>> listByDto(CouponStore couponStore) {
        return Result.success(couponStoreService.listByDto(couponStore));
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     */
    @DeleteMapping("/deleteById/{id}")
    @PreAuthorize("@ss.hasPermi('/couponStore/deleteById/{id}')")
    @ApiOperation("通过id删除券可用店铺数据(物理删除)")
    public Result<Integer> deleteById(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(couponStoreService.deleteById(id));
    }

    /**
     * 通过id数组删除(物理删除)
     * 
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/couponStore/deleteByIds/{ids}')")
    @ApiOperation("通过id数组删除券可用店铺数据(物理删除)")
    public Result<Integer> deleteByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(couponStoreService.deleteByIds(ids));
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param couponStore
     * @return
     */
    @PutMapping("/updateAllById")
    @PreAuthorize("@ss.hasPermi('/couponStore/updateAllById')")
    @ApiOperation("通过id更新券可用店铺数据(全部更新)")
    public Result<Integer> updateAllById(@RequestBody CouponStore couponStore) {
        return Result.success(couponStoreService.updateAllById(couponStore));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param couponStore
     * @return
     */
    @PutMapping("/updateAllByIdList")
    @PreAuthorize("@ss.hasPermi('/couponStore/updateAllByIdList')")
    @ApiOperation("通过id列表更新券可用店铺数据(全部更新)(更新内容相同)")
    public Result<Integer> updateAllByIdList(@RequestBody CouponStore couponStore) {
        return Result.success(couponStoreService.updateAllByIdList(couponStore));
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param couponStore
     * @return
     */
    @PutMapping("/updateDtoListAllById")
    @PreAuthorize("@ss.hasPermi('/couponStore/updateDtoListAllById')")
    @ApiOperation("通过id列表更新券可用店铺数据(全部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListAllById(@RequestBody CouponStore couponStore) {
        return Result.success(couponStoreService.updateDtoListAllById(couponStore));
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param couponStore
     * @return
     */
    @PutMapping("/updateById")
    @PreAuthorize("@ss.hasPermi('/couponStore/updateById')")
    @ApiOperation("通过id更新券可用店铺数据(局部更新)")
    public Result<Integer> updateById(@RequestBody CouponStore couponStore) {
        // 校验参数
        Result<Integer> paramResult = CouponStoreParamVerify.updateById(couponStore);
        // 验证不通过
        if (!paramResult.getCode().equals(TransErrorCode.SUCCESS.getCode())) {
            return paramResult;
        }

        couponStore.updateInit();
        couponStore.setUpdateNull();
        return Result.success(couponStoreService.updateById(couponStore));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param couponStore
     * @return
     */
    @PutMapping("/updateByIdList")
    @PreAuthorize("@ss.hasPermi('/couponStore/updateByIdList')")
    @ApiOperation("通过id列表更新券可用店铺数据(局部更新)(更新内容相同)")
    public Result<Integer> updateByIdList(@RequestBody CouponStore couponStore) {
        return Result.success(couponStoreService.updateByIdList(couponStore));
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param couponStore
     * @return
     */
    @PutMapping("/updateDtoListById")
    @PreAuthorize("@ss.hasPermi('/couponStore/updateDtoListById')")
    @ApiOperation("通过id列表更新券可用店铺数据(局部更新)(更新内容不相同)")
    public Result<Integer> updateDtoListById(@RequestBody CouponStore couponStore) {
        return Result.success(couponStoreService.updateDtoListById(couponStore));
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @PreAuthorize("@ss.hasPermi('/couponStore/findById/{id}')")
    @ApiOperation("通过id查询券可用店铺数据")
    public Result<CouponStore> findById(@PathVariable Integer id) {
        if (id == null) {
            return Result.success();
        }

        return Result.success(couponStoreService.findById(id));
    }

    /**
     * 通过id数组查询
     * 
     * @param ids
     * @return
     */
    @GetMapping("/findByIds/{ids}")
    @PreAuthorize("@ss.hasPermi('/couponStore/findByIds/{ids}')")
    @ApiOperation("通过id数组查询券可用店铺数据")
    public Result<List<CouponStore>> findByIds(@PathVariable Integer[] ids) {
        if (ids.length == 0) {
            return Result.success();
        }

        return Result.success(couponStoreService.findByIds(ids));
    }

    /**
     * 通过对象查询id列表
     * 
     * @param couponStore
     * @return
     */
    @GetMapping("/findIdByDto")
    @PreAuthorize("@ss.hasPermi('/couponStore/findIdByDto')")
    @ApiOperation("通过对象查询券可用店铺id列表")
    public Result<List<Integer>> findIdByDto(CouponStore couponStore) {
        return Result.success(couponStoreService.findIdByDto(couponStore));
    }

    /**
     * 清空数据(物理清空)
     * 
     * @return
     */
    @DeleteMapping("/clear")
    @PreAuthorize("@ss.hasPermi('/couponStore/clear')")
    @ApiOperation("清空券可用店铺数据(物理清空)")
    public Result<Integer> clear() {
        return Result.success(couponStoreService.clear());
    }

    /**
     * 根据对象查询
     * 
     * @param couponStore
     * @return
     */
    @GetMapping(value = "/list")
    @PreAuthorize("@ss.hasPermi('/couponStore/list')")
    public Object list(CouponStore couponStore) {
        List<CouponStore> list = couponStoreService.list(couponStore);
        return Result.success(list);
    }

}